<%@page import="com.crm.entity.Sources,java.util.*,com.crm.util.Constants" %>
<%@page import="com.crm.entity.Parts"%>
<%@page import="com.crm.entity.Supplier"%>
<%
List<Parts> partslist=(List<Parts>)request.getAttribute("partlist");
List<Supplier> suplist=(List<Supplier>)request.getAttribute("supplier");
System.out.println("Jsp Result of partslist  "+request.getAttribute("partlist"));
System.out.println("the list of parts in jsp  "+partslist);
%>
<script type="text/javascript">
$(function(){
	  $("#userTable").colResizable();
	});
</script>
 <input type="hidden" name="rowcount" value="<%=partslist.size()%>" id="columnCount"/>
             <input type="hidden" name="initcount" value="<%=partslist.size()%>" id="initCount"/>
 <table id="userTable"  border="0"  style="width:919px;" cellpadding="4" cellspacing="1" bgcolor="#C5E4EB">
          <tr>
           <td width="20"  align="left" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"  style="background-repeat:repeat-x"></td>
            <td width="20"  align="left" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"  style="background-repeat:repeat-x">S.No</td>
            <td width="32" align="left" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Part Number</td>
            <td width="32" align="left" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Description</td>
            <td width="32" align="left" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Make</td>
            <td width="20" align="left" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Req Qty</td>
            <td width="34" align="left" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">OfferingPartno</td>
            <td width="37" align="left" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Supplier</td>
            <td width="27" align="left" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Unit Price</td>
            <td width="34" align="left" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Currency</td>
            <td width="20" align="left" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Qty Available</td>
            <td width="23" align="left" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">M.O.Q</td>
            <td width="23" align="left" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">S.P.Q</td>
            <td width="36" align="left" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Conditions</td>
             </tr> 
        <% if(partslist.size()>0){
        	System.out.println("the size of the pr list is "+suplist.size());
             for(int i=0;i<partslist.size();i++){  %>
        
          <tr>
          <td bgcolor="#FFFFFF">
          <input type="checkbox" name="idname" value="<%=i+1%>" /></td>
            <td bgcolor="#FFFFFF">
            <input name="sno" type="text" value="<%=i+1%>" size="5" />
            </td>
            <td align="left" valign="top" bgcolor="#FFFFFF">
            <input name="partno<%=i+1 %>"  id="partno<%=i+1 %>"  class="part" type="text" value="<%=partslist.get(i).getPrtnum() %>"  size="5"/><input name="partid<%=i+1 %>"   class="part" type="hidden" value="<%=partslist.get(i).getPartid() %>"  size="5"/></td>
            <td align="left" valign="top" bgcolor="#FFFFFF">
            <input name="desc<%=i+1 %>"  id="desc<%=i+1 %>" type="text" value="<%=partslist.get(i).getDescription() %>"  size="5"/></td>
            <td align="left" valign="top" bgcolor="#FFFFFF">
            <input name="make<%=i+1 %>" id="make<%=i+1 %>" type="text"   value="<%=partslist.get(i).getMake() %>" size="5" /></td>
           <td align="left" valign="top" bgcolor="#FFFFFF">
            <input name="rqty<%=i+1%>" id="rqty<%=i+1%>" type="text" value="<%=partslist.get(i).getQty() %>" size="5" /></td>
             <td align="left" valign="top" bgcolor="#FFFFFF">
            <input name="opartno<%=i+1 %>" id="opartno<%=i+1 %>" type="text" value="<%=partslist.get(i).getPrtnum()%>" size="5" /></td>
            <td align="left" valign="top" bgcolor="#FFFFFF">
            <select name="supplier<%=i+1%>"  id="supplier<%=i+1%>" style="border: 0px"  >
         <%
	      	for(int j=0;j<suplist.size();j++){ 
	      		
	      	%>
           <option  value="<%=suplist.get(j).getName()%>"><%=suplist.get(j).getName()%></option>
                   	<%
	              	}%>
                </select></td>
            <td align="left" valign="top" bgcolor="#FFFFFF">
            <input name="uprice<%=i+1 %>"  id="uprice<%=i+1 %>" type="text" value="" size="5" /></td>
            
            <td align="left" valign="top" bgcolor="#FFFFFF">
           <select name="currency<%=i+1%>" id="currency<%=i+1%>"  style="border:0px" id="currency" >
           <option value="<%=Constants.ST_CUR_RUPEE%>">INR RS</option>
           <option value="<%=Constants.ST_CUR_DOLLAR%>" selected="selected">Doller($)</option>
           <option value="<%=Constants.ST_CUR_SDOLLAR%>">Singpore Doller(S$)</option>
           <option value="<%=Constants.ST_CUR_YEN%>">Yen</option>
           <option value="<%=Constants.ST_CUR_EURO%>">Euro</option>
           <option value="<%=Constants.ST_CUR_POUND%>">Pound</option></select></td>
           
            <td align="left" valign="top" bgcolor="#FFFFFF">
            <input name="qtyable<%=i+1 %>" id="qtyable<%=i+1 %>" type="text" value="<%=partslist.get(i).getQty() %>" size="5" /></td>
            
            <td align="left" valign="top" bgcolor="#FFFFFF">
            <input name="moq<%=i+1 %>" id="moq<%=i+1 %>"  type="text" value="<%=partslist.get(i).getQty() %>" size="5" /></td>
            <td align="left" valign="top" bgcolor="#FFFFFF">
            <input name="spq<%=i+1 %>" id="spq<%=i+1 %>" type="text" value="<%=partslist.get(i).getQty() %>" size="5" /></td>
          <td align="left" valign="top" bgcolor="#FFFFFF">
            <input name="conditions<%=i+1 %>" id="conditions<%=i+1 %>" type="text" value="" size="5" /></td>
      
          </tr>
      
          <%} 
          }
          %>  
        </table>
        <div class="box2">
	 <table><tr><td align="left"> <input type="button" id="rsupid"class="button"  onclick="javascript: deleteRow('userTable')" value="Remove Supplier"/>
	 <input  id="addsupid" type="button" class="button"  onclick="javascript: AddSelRow('userTable')"  value="Add Supplier"/>
	  </td></tr></table>
	    <div class="buttton-main">
	    <input type="submit" class="button" value="Import From Source" onclick="javascript : processFormData();"/>
	    <input type="button" class="button" onclick="javascript:return  remsource();" value="Source Complete"/>
	    </div>
	  </div>
<script type="text/javascript">
	$(function(){
		 var client="<%=request.getAttribute("clientdet")%>";
		 var cldiv="<%=request.getAttribute("division")%>";
		 var cluser="<%=request.getAttribute("user")%>";
		 $("#enqclient").html("Client Name Is:<span class='cliendet'>"+client +
		"</span>   &nbsp;&nbsp;&nbsp;&nbsp;  Client Division Is:<span class='cliendet'>"+cldiv+
		 "</span>    &nbsp;&nbsp;&nbsp;&nbsp;    Client User Is:<span class='cliendet'>"+cluser+"</span>");
		 $("#enqclient").show();
	});
        function addRowData(rowin,userTable) {
        	 //alert("the VAlue of rowin"+rowin);
            var table = document.getElementById(userTable);
           
            var rowCount = table.rows.length;
            
 			var ActualCount = $('#columnCount').val();// document.getElementById(columnCount);
 			/* alert("actualcount is "+ActualCount);
 			alert("RowCountis is "+rowCount); */
 		ActualCount++; 
			var row = table.insertRow(rowCount);
			
			//alert("Rowvalue  is "+row);
			table.setAttribute("bgColor", "#C5E4EB");
			
			 var cell0=row.insertCell(0);
			    cell0.setAttribute("bgColor","#FFFFFF");
			    cell0.innerHTML='<input type="checkbox" name="idname" value="'+ActualCount+'" />';
			    	
		    var cell1 = row.insertCell(1);
		    cell1.innerHTML = rowCount ;
           	cell1.setAttribute("bgColor","#FFFFFF");
                      	
            var cell2 = row.insertCell(2);
            cell2.setAttribute("bgColor","#FFFFFF");
        	var val=document.getElementById("partno"+rowin);
            cell2.innerHTML='<input type="text" name="partno'+ActualCount+'"  class="part" size="5" value="'+val.value+'" id="partno'+ActualCount+'"  />';
            
            var cell3 = row.insertCell(3);
            cell3.setAttribute("bgColor","#FFFFFF");
        	var val=document.getElementById("desc"+rowin);
            cell3.innerHTML='<input type="text" name="desc'+ActualCount+'"  size="5" value="'+val.value+'" id="desc'+ActualCount+'"  />';
            
            var cell4 = row.insertCell(4);
            cell4.setAttribute("bgColor","#FFFFFF");
        	var val=document.getElementById("make"+rowin);
            cell4.innerHTML='<input type="text" name="make'+ActualCount+'"  size="5" value="'+val.value+'" id="make'+ActualCount+'"  />';
            
            var cell5 = row.insertCell(5);
            cell5.setAttribute("bgColor","#FFFFFF");
        	var val=document.getElementById("rqty"+rowin);
            cell5.innerHTML='<input type="text" name="rqty'+ActualCount+'" size="5"  value="'+val.value+'" id="rqty'+ActualCount+'"  />';
            
            var cell6 = row.insertCell(6);
            cell6.setAttribute("bgColor","#FFFFFF");
        	var val=document.getElementById("opartno"+rowin);
            cell6.innerHTML='<input type="text" name="opartno'+ActualCount+'"  size="5" value="'+val.value+'" id="opartno'+ActualCount+'"  />';
            
            var cell7 = row.insertCell(7);
            cell7.setAttribute("bgColor","#FFFFFF");
           
            var opts = document.getElementById("supplier"+rowin).options;
            var vals = [];
            for(var i = 0, j = opts.length; i < j; i++) 
               vals.push(opts[i].value);

        	var sel=document.getElementById("supplier"+rowin); 
        	var arr= sel.value;
            cell7.innerHTML='<select name="supplier'+ActualCount+'"  id="supplier'+ActualCount+'"   style="border: 0px">'+
            '</select>';
           
            var opts=document.getElementById("supplier"+rowin).options;
            
    		var e2=document.getElementById("supplier"+ActualCount);
             for(var i = 0, j = opts.length; i < j; i++) 
    {
    		var o=document.createElement('option');
    		o.value=opts[i].value;
    		o.text=opts[i].value;
    		e2.options.add(o);
    }
            
            var cell8 = row.insertCell(8);
            cell8.setAttribute("bgColor","#FFFFFF");
        	var val=document.getElementById("uprice"+rowin);
            cell8.innerHTML='<input type="text" name="uprice'+ActualCount+'"  size="5" value="'+val.value+'" id="uprice'+ActualCount+'"  />';
            
            var cell9 = row.insertCell(9);
            cell9.setAttribute("bgColor","#FFFFFF");
        	var val=document.getElementById("currency"+rowin);
            cell9.innerHTML='<select name="currency'+ActualCount+'" id="currency'+ActualCount+'"  style="border: 0px" id="currency" >'+
            '<option value="rs">INR RS</option>'+
                '<option value="doller">Doller($)</option>'+
                '<option value="sdoller">Singpore Doller(S$)</option>'+
                '<option value="yen">Yen</option>'+
                '<option value="pound">Pound</option></select>';
            
                var cell10 = row.insertCell(10);
                cell10.setAttribute("bgColor","#FFFFFF");
            	var val=document.getElementById("qtyable"+rowin);
                cell10.innerHTML='<input type="text" name="qtyable'+ActualCount+'"  size="5" value="'+val.value+'" id="qtyable'+ActualCount+'"  />';
                
                var cell11 = row.insertCell(11);
                cell11.setAttribute("bgColor","#FFFFFF");
            	var val=document.getElementById("moq"+rowin);
                cell11.innerHTML='<input type="text" name="moq'+ActualCount+'"  size="5" value="'+val.value+'" id="moq'+ActualCount+'"  />';
                
                var cell12 = row.insertCell(12);
                cell12.setAttribute("bgColor","#FFFFFF");
            	var val=document.getElementById("spq"+rowin);
                cell12.innerHTML='<input type="text" name="spq'+ActualCount+'"  size="5" value="'+val.value+'" id="spq'+ActualCount+'"  />';
                
                var cell13 = row.insertCell(13);
                cell13.setAttribute("bgColor","#FFFFFF");
            	var val=document.getElementById("conditions"+rowin);
                cell13.innerHTML='<input type="text" name="conditions'+ActualCount+'"  size="5" value="'+val.value+'" id="conditions'+ActualCount+'"  />';
              
              
            
                $('#columnCount').val(ActualCount);
                
        }
 
      
    	function addItem(){
    		var e1=document.getElementById('item');
    		var e2=document.getElementById('items');
    		var o=document.createElement('option');
    		o.value=e1.value;
    		o.text=e1.value;
    		e2.options.add(o);
    	}
 
        function deleteRow(userTable) {
            try {
            	var val = [];
		        $(':checkbox:checked').each(function(j){
		          val[j] = $(this).val();
		        });
		        if (val=="")
		        {
		        	 jAlert("Select the Row of box U want Delete");
		        }

            var table = document.getElementById(userTable);
            var rowCount = table.rows.length;
            for(var i=0; i<rowCount; i++) {
                var row = table.rows[i];
                var chkbox = row.cells[0].childNodes[0];
              
                if(null != chkbox && true == chkbox.checked) {
                    table.deleteRow(i);
                    rowCount--;
                    i--;
                }
            }
			for(var i=0; i<rowCount-1; i++)
           table.rows[i+1].cells[1].innerHTML = i+1;
            }catch(e) {
                //alert(e);
            }
        }
        function AddSelRow(userTable) {	
        
            var table = document.getElementById(userTable);
            var rowCount = table.rows.length;
                	var val = [];
    		        $(':checkbox:checked').each(function(j){
    		          val[j] = $(this).val();
    		          addRowData(val[j],userTable);
    		        });
    		        if (val=="")
    		        {
    		        	 jAlert("Select the Row of box U want Add");
    		        }
 
            }
        
     </script>
  


	  